import React from 'react';
import {
    View,
    Text,StyleSheet,
} from 'react-native';
import DetailFooter from "../components/question/DetailFooter";
import {getQuestionById} from "../service/question";

class QuestionDetail extends React.PureComponent{
    static navigatorStyle = {
        tabBarHidden:true,
        navBarCustomView:'interview.questionTopNav'
    }
    constructor(props){
        super(props);

        this.state = {
            data:null,
            question:''
        }
    }
    componentWillMount(){
        console.log(this.props);
        this.setState({
            question:this.props.question
        })
    }
    componentDidMount(){

        this.getQuestion(this.props.id)
    }
    render(){
        return (
            <View style={styles.container}>
                <View style={styles.container}>
                <Text>{this.state.question}</Text>
                    {this.content}
                </View>
                {/*{this.footer}*/}
            </View>
        )
    }

    get content(){
        const {data} = this.state;
        if(!data)return null;
        return <Text>{data.answer}</Text>
    }

    get footer(){
        return <DetailFooter/>
    }

    async getQuestion(id){
        try{
            const result = await getQuestionById(id);
            // console.log('问题',result);
            this.setState({
                data:result.toJSON()
            })
        }catch (e){

        }
    }
}

const styles = StyleSheet.create({
    container:{
        flex:1
    }
});

export default QuestionDetail;